# -*- coding: utf-8 -*-

import socket

# 目的ip地址与端口
dest_ip = "fe80::4c6a:f242:86d2:1511"
dest_port = 10000

# 创建套接字
sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM, socket.IPPROTO_UDP)

# 绑定到指定的IPv6地址和端口
sock.bind((dest_ip, dest_port))

print(f"Listening on addr =  {dest_ip} port = {dest_port}")

try:
    while True:
        # 接收数据
        data, addr = sock.recvfrom(1024)  # 缓冲区大小设置为1024字节
        print(f"Received data from {addr}:")
        print(f"Data: {' '.join(format(x, '02x') for x in data)}")
        print()

except KeyboardInterrupt:
    print("\nProgram terminated by user")

finally:
    # 关闭套接字
    sock.close()